package com.weiiew.recipeservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.weiiew.common.entity.cal.TranslationRecipe;
import com.weiiew.common.entity.cal.calRecipe;
import com.weiiew.common.entity.cal.calRecipeItem;
import com.weiiew.common.entity.dto.Recipe;
import com.weiiew.common.entity.simple.DoublePair;
import com.weiiew.common.entity.simple.SimpleBuilding;
import com.weiiew.common.entity.simple.SimpleItem;
import com.weiiew.common.entity.vo.RecipeItemVO;
import com.weiiew.common.entity.vo.RecipeVO;
import com.weiiew.common.entity.qo.RecipeQo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 魏锴
 * @description 针对表【recipe】的数据库操作Mapper
 * @createDate 2024-01-28 01:49:55
 * @Entity com.example.adminBackEnd.Entity.dao.Recipe
 */
@Mapper
public interface RecipeMapper extends BaseMapper<Recipe> {
    void insertRecipe(Recipe recipe);
    void updateRecipe(Recipe recipe);

    List<RecipeItemVO> getIngredientsById(Long recipe_id);

    List<RecipeItemVO> getProductsById(Long recipe_id);
    List<calRecipeItem> getCalIngredientsById(long id);

    List<calRecipeItem> getCalProductsById(long id);

    List<SimpleBuilding> getBuildingsById(Integer recipe_id);


    List<RecipeVO> getList(RecipeQo qo);

    Integer getCount(RecipeQo qo);

    List<SimpleItem> getItemListSortByProduct(Integer version);

    List<SimpleItem> getItemListSortByIngredient(Integer version);

    List<SimpleBuilding> getBuildListSortByBuilding(Integer version);

    List<RecipeVO> getRecipeByBuildingId(@Param("build") Integer build);

    List<RecipeVO> getRecipeByIngredientId(@Param("item") Integer item);

    List<RecipeVO> getRecipeByProductId(@Param("item") Integer item);



    //获取
    @Select("select recipe_id from recipe_product where recipe_id != #{recipe} and item_id = #{item} limit 1;")
    Long getFirstRecipeByProductId(@Param("item") int item, @Param("recipe") long recipe);

    void setDefaultRecipeIfNull(@Param("id") int id, @Param("recipe") long recipe);
    @Select("select id from item where default_recipe = #{id}")
    List<Integer> getItemListByDefaultRecipe(long id);

    @Update("update item set default_recipe = #{recipe} where id = #{item}")
    void setDefaultRecipe(@Param("recipe") Long recipe, @Param("item") Integer item);

    List<calRecipe> getCalRecipeByItem(@Param("version") Integer version, @Param("item") Integer item);

    List<DoublePair> getFactoryRecipeById(Integer id);

    TranslationRecipe getTranslationRecipe(@Param("item") int item, @Param("recipe") int recipe);

    RecipeVO getRecipeVOById(Integer id);
}




